package com.htc.model.utils;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;

public class ChangeLogModel {
	public static ChangeLogModel instance;

	public static ChangeLogModel getInstance() {
		if (instance == null)
			instance = new ChangeLogModel();
		return instance;
	}

	// @SuppressWarnings("unused")
	// private ChangeLogDTO ChangeLogDTO(Context context) {
	// String sql = "Select Id FROM change_log ORDER BY Id DESC LIMIT 1";
	// DBHelper db = new DBHelper(context);
	// Cursor c = db.Excutequery(sql);
	// ChangeLogDTO dto = new ChangeLogDTO();
	// dto.setId(c.getInt(c.getColumnIndex("Id")));
	// return dto;
	// }

	public int getIdChangeLog(Context context) {
		int id = 0;
		String sql = "SELECT * FROM change_log";
		DBHelper db = new DBHelper(context);
		Cursor c = db.Excutequery(sql);

		id = c.moveToLast() == true ? c.getInt(c.getColumnIndex("change_log_id")) : 0;

		return id;
	}

//	public boolean checkIdEvent(String table, int id, Context context) {
//		boolean flag = false;
//		String sql = "SELECT * FROM " + table + " where Id= " + id;
//		DBHelper db = new DBHelper(context);
//		Cursor c = db.Excutequery(sql);
//		flag = c.moveToFirst();
//		return flag;
//	}

	public boolean updateChanglog(int id, Context context) {
		boolean flag = false;
		// String sql = "UPDATE changelog SET Id=" + id;
		DBHelper db = new DBHelper(context);
		ContentValues values = new ContentValues();
		values.put("change_log_id", id);
		flag = db.ExcuteUpdate(null, "change_log", values, "1 = 1", null);
		return flag;
	}
}
